<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <title>centos 升级内核 | 清峰小栈</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  
  <meta name="keywords" content="centos" />
  
  
  
  
  <meta name="description" content="CentOS 升级内核的三种方式(yum&#x2F;rpm&#x2F;源码) 在 CentOS 使用过程中，难免需要升级内核，但有时候因为源码编译依赖问题，不一定所有程序都支持最新内核版本，所以以下将介绍三种升级内核方式。  注意事项123关于内核种类:kernel-ml 中的ml是英文【 mainline stable 】的缩写，elrepo-kernel中罗列出来的是最新的稳定主线版本。ker">
<meta property="og:type" content="article">
<meta property="og:title" content="CentOS 升级内核">
<meta property="og:url" content="http://example.com/2023/02/08/Linux/CentOS%20%E5%8D%87%E7%BA%A7%E5%86%85%E6%A0%B8/index.html">
<meta property="og:site_name" content="清峰小栈">
<meta property="og:description" content="CentOS 升级内核的三种方式(yum&#x2F;rpm&#x2F;源码) 在 CentOS 使用过程中，难免需要升级内核，但有时候因为源码编译依赖问题，不一定所有程序都支持最新内核版本，所以以下将介绍三种升级内核方式。  注意事项123关于内核种类:kernel-ml 中的ml是英文【 mainline stable 】的缩写，elrepo-kernel中罗列出来的是最新的稳定主线版本。ker">
<meta property="og:locale" content="en_US">
<meta property="article:published_time" content="2023-02-08T07:42:12.147Z">
<meta property="article:modified_time" content="2023-04-28T06:34:13.888Z">
<meta property="article:author" content="清峰">
<meta property="article:tag" content="centos">
<meta name="twitter:card" content="summary">
  

  

  <link rel="icon" href="/qingfeng-blog/css/images/mylogo-2.png">
  <link rel="apple-touch-icon" href="/qingfeng-blog/css/images/mylogo-2.png">
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  <link href="https://fonts.googleapis.com/css?family=Open+Sans|Montserrat:700" rel="stylesheet" type="text/css">
  <link href="https://fonts.googleapis.com/css?family=Roboto:400,300,300italic,400italic" rel="stylesheet" type="text/css">
  <!-- <link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet"> -->
  <link href="/qingfeng-blog/css/font-awesome.css" rel="stylesheet">
  <style type="text/css">
    @font-face{font-family:futura-pt; src:url("/qingfeng-blog/css/fonts/FuturaPTBold.otf") format("woff");font-weight:500;font-style:normal;}
    @font-face{font-family:futura-pt-light; src:url("/qingfeng-blog/css/fonts/FuturaPTBook.otf") format("woff");font-weight:lighter;font-style:normal;}
    @font-face{font-family:futura-pt-italic; src:url("/qingfeng-blog/css/fonts/FuturaPTBookOblique.otf") format("woff");font-weight:400;font-style:italic;}
}

  </style>
  
<link rel="stylesheet" href="/qingfeng-blog/css/style.css">


  
<script src="/qingfeng-blog/js/jquery-3.1.1.min.js"></script>

  
<script src="/qingfeng-blog/js/bootstrap.js"></script>


  <!-- Bootstrap core CSS -->
  <link rel="stylesheet" href="/qingfeng-blog/css/bootstrap.css" >

  
    
<link rel="stylesheet" href="/qingfeng-blog/css/dialog.css">

  

  

  
    <link rel="stylesheet" href="/qingfeng-blog/css/header-post.css" >
  

  
  
  
    <link rel="stylesheet" href="/qingfeng-blog/css/vdonate.css" >
  

<meta name="generator" content="Hexo 6.3.0"></head>



  <body data-spy="scroll" data-target="#toc" data-offset="50">


  
  <div id="container">
    <div id="wrap">
      
        <header>

    <div id="allheader" class="navbar navbar-default navbar-static-top" role="navigation">
        <div class="navbar-inner">
          
          <div class="container"> 
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
              <span class="sr-only">Toggle navigation</span>
              <span class="icon-bar"></span>
              <span class="icon-bar"></span>
              <span class="icon-bar"></span>
            </button>

            
              <a class="brand" style="
                 border-width: 0px;  margin-top: 0px;"  
                href="#" data-toggle="modal" data-target="#myModal" >
                  <img width="155px" height="90px" alt="Hike News" src="/qingfeng-blog/css/images/mylogo-2.png">
              </a>
            
            
            <div class="navbar-collapse collapse">
              <ul class="hnav navbar-nav">
                
                  <li> <a class="main-nav-link" href="/qingfeng-blog/">首页</a> </li>
                
                  <li> <a class="main-nav-link" href="/qingfeng-blog/categories">分类</a> </li>
                
                  <li> <a class="main-nav-link" href="/qingfeng-blog/tags">标签</a> </li>
                
                  <li><div id="search-form-wrap">

    <form class="search-form">
        <input type="text" class="ins-search-input search-form-input" placeholder="" />
        <button type="submit" class="search-form-submit"></button>
    </form>
    <div class="ins-search">
    <div class="ins-search-mask"></div>
    <div class="ins-search-container">
        <div class="ins-input-wrapper">
            <input type="text" class="ins-search-input" placeholder="Type something..." />
            <span class="ins-close ins-selectable"><i class="fa fa-times-circle"></i></span>
        </div>
        <div class="ins-section-wrapper">
            <div class="ins-section-container"></div>
        </div>
    </div>
</div>
<script>
(function (window) {
    var INSIGHT_CONFIG = {
        TRANSLATION: {
            POSTS: 'Posts',
            PAGES: 'Pages',
            CATEGORIES: 'Categories',
            TAGS: 'Tags',
            UNTITLED: '(Untitled)',
        },
        ROOT_URL: '/qingfeng-blog/',
        CONTENT_URL: '/qingfeng-blog/content.json',
    };
    window.INSIGHT_CONFIG = INSIGHT_CONFIG;
})(window);
</script>

<script src="/qingfeng-blog/js/insight.js"></script>


</div></li>
            </div>
          </div>
                
      </div>
    </div>

</header>



      
            
      <div id="content" class="outer">
        
          <section id="main" style="float:none;"><article id="post-Linux/CentOS 升级内核" style="width: 75%; float:left;" class="article article-type-post" itemscope itemprop="blogPost" >
<div id="container">
  <div id="articleInner" class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="thumb" class="article-title" itemprop="name">
      CentOS 升级内核
    </h1>
  

      </header>
    
    <div class="article-meta">
      
	<a href="/qingfeng-blog/2023/02/08/Linux/CentOS%20%E5%8D%87%E7%BA%A7%E5%86%85%E6%A0%B8/" class="article-date">
	  <time datetime="2023-02-08T07:42:12.147Z" itemprop="datePublished">2023-02-08</time>
	</a>

      
    <a class="article-category-link" href="/qingfeng-blog/categories/Linux/">Linux</a>

      
	<a class="article-views">
	<span id="busuanzi_container_page_pv">
		PV:<span id="busuanzi_value_page_pv"></span>
	</span>
	</a>

      

    </div>
    <div class="article-entry" itemprop="articleBody">
      
        <h1 id="CentOS-升级内核的三种方式-yum-x2F-rpm-x2F-源码"><a href="#CentOS-升级内核的三种方式-yum-x2F-rpm-x2F-源码" class="headerlink" title="CentOS 升级内核的三种方式(yum&#x2F;rpm&#x2F;源码)"></a>CentOS 升级内核的三种方式(yum&#x2F;rpm&#x2F;源码)</h1><blockquote>
<p>在 CentOS 使用过程中，难免需要升级内核，但有时候因为源码编译依赖问题，不一定所有程序都支持最新内核版本，所以以下将介绍三种升级内核方式。</p>
</blockquote>
<h3 id="注意事项"><a href="#注意事项" class="headerlink" title="注意事项"></a>注意事项</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">关于内核种类:</span><br><span class="line">kernel-ml 中的ml是英文【 mainline stable 】的缩写，elrepo-kernel中罗列出来的是最新的稳定主线版本。</span><br><span class="line">kernel-lt 中的lt是英文【 long term support 】的缩写，elrepo-kernel中罗列出来的长期支持版本。</span><br></pre></td></tr></table></figure>


<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 检查内核版本</span></span><br><span class="line"><span class="built_in">uname</span> -r</span><br></pre></td></tr></table></figure>

<h2 id="一、yum安装"><a href="#一、yum安装" class="headerlink" title="一、yum安装"></a>一、yum安装</h2><h3 id="1、导入仓库源"><a href="#1、导入仓库源" class="headerlink" title="1、导入仓库源"></a>1、导入仓库源</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org</span><br><span class="line"></span><br><span class="line">rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm</span><br></pre></td></tr></table></figure>

<h3 id="2、查看可安装的软件包"><a href="#2、查看可安装的软件包" class="headerlink" title="2、查看可安装的软件包"></a>2、查看可安装的软件包</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum --enablerepo=&quot;elrepo-kernel&quot; list --showduplicates | sort -r | grep kernel-ml.x86_64</span><br></pre></td></tr></table></figure>

<h3 id="3、选择-ML-或-LT-版本安装"><a href="#3、选择-ML-或-LT-版本安装" class="headerlink" title="3、选择 ML 或 LT 版本安装"></a>3、选择 ML 或 LT 版本安装</h3><p>无指定版本默认安装最新</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"># 安装 ML 版本</span><br><span class="line">yum --enablerepo=elrepo-kernel install  kernel-ml-devel kernel-ml -y   </span><br><span class="line"></span><br><span class="line"># 安装 LT 版本，K8S全部选这个</span><br><span class="line">yum --enablerepo=elrepo-kernel install kernel-lt-devel kernel-lt -y</span><br></pre></td></tr></table></figure>

<h3 id="4、查看现有内核启动顺序"><a href="#4、查看现有内核启动顺序" class="headerlink" title="4、查看现有内核启动顺序"></a>4、查看现有内核启动顺序</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">awk -F\&#x27; &#x27;$1==&quot;menuentry &quot; &#123;print $2&#125;&#x27; /etc/grub2.cfg</span><br></pre></td></tr></table></figure>

<h3 id="5、修改默认启动项"><a href="#5、修改默认启动项" class="headerlink" title="5、修改默认启动项"></a>5、修改默认启动项</h3><p>xxx 为序号数字，以指定启动列表中第x项为启动项，x从0开始计数</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">grub2-set-default xxxx</span><br></pre></td></tr></table></figure>

<p><strong>例如设置以4.4内核启动</strong></p>
<p>则直接输入“grub2-set-default 0”，下次启动即可从4.4启动</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"># 查看内核启动序号</span><br><span class="line">[root@localhost ~] awk -F\&#x27; &#x27;$1==&quot;menuentry &quot; &#123;print $2&#125;&#x27; /etc/grub2.cfg</span><br><span class="line"></span><br><span class="line">CentOS Linux (4.4.179-1.el7.elrepo.x86_64) 7 (Core)</span><br><span class="line"></span><br><span class="line">CentOS Linux (3.10.0-693.el7.x86_64) 7 (Core)</span><br><span class="line"></span><br><span class="line">CentOS Linux (0-rescue-6d4c599606814867814f1a8eec7bfd1e) 7 (Core)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"># 设置启动序号</span><br><span class="line">[root@localhost ~] grub2-set-default 0</span><br><span class="line"></span><br><span class="line"># 重启</span><br><span class="line">reboot</span><br><span class="line"></span><br><span class="line"># 检查内核版本</span><br><span class="line">uname -r</span><br></pre></td></tr></table></figure>



<h2 id="二、RPM安装"><a href="#二、RPM安装" class="headerlink" title="二、RPM安装"></a>二、RPM安装</h2><p>检查内核版本</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">uname -r</span><br></pre></td></tr></table></figure>



<h3 id="1、查找版本"><a href="#1、查找版本" class="headerlink" title="1、查找版本"></a>1、查找版本</h3><p>因 ELRepo 源都是最新版本，所以旧版本内核只能手动下载。</p>
<p>查找 kernel rpm 历史版：</p>
<p><a target="_blank" rel="noopener" href="http://mirrors.coreix.net/elrepo-archive-archive/kernel/el7/x86_64/RPMS/">http://mirrors.coreix.net/elrepo-archive-archive/kernel/el7/x86_64/RPMS/</a></p>
<h3 id="2、共需要下载三个类型-rpm"><a href="#2、共需要下载三个类型-rpm" class="headerlink" title="2、共需要下载三个类型 rpm"></a>2、共需要下载三个类型 rpm</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">wget http://mirrors.coreix.net/elrepo-archive-archive/kernel/el7/x86_64/RPMS/kernel-lt-devel-4.4.215-1.el7.elrepo.x86_64.rpm</span><br><span class="line">wget http://mirrors.coreix.net/elrepo-archive-archive/kernel/el7/x86_64/RPMS/kernel-lt-headers-4.4.215-1.el7.elrepo.x86_64.rpm</span><br><span class="line">wget http://mirrors.coreix.net/elrepo-archive-archive/kernel/el7/x86_64/RPMS/kernel-lt-4.4.215-1.el7.elrepo.x86_64.rpm</span><br></pre></td></tr></table></figure>

<h3 id="3、安装内核"><a href="#3、安装内核" class="headerlink" title="3、安装内核"></a>3、安装内核</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">rpm -ivh kernel-lt-4.4.215-1.el7.elrepo.x86_64.rpm</span><br><span class="line">rpm -ivh kernel-lt-devel-4.4.215-1.el7.elrepo.x86_64.rpm</span><br><span class="line">或者</span><br><span class="line">#一键安装所有</span><br><span class="line">rpm -Uvh *.rpm</span><br></pre></td></tr></table></figure>

<h3 id="4、确认已安装内核版本"><a href="#4、确认已安装内核版本" class="headerlink" title="4、确认已安装内核版本"></a>4、确认已安装内核版本</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">[root@localhost ~]# rpm -qa | grep kernel</span><br><span class="line">kernel-headers-3.10.0-1160.15.2.el7.x86_64</span><br><span class="line">kernel-devel-3.10.0-1160.49.1.el7.x86_64</span><br><span class="line">kernel-tools-libs-3.10.0-957.el7.x86_64</span><br><span class="line">kernel-3.10.0-957.el7.x86_64</span><br><span class="line">kernel-ml-4.9.9-1.el7.elrepo.x86_64</span><br><span class="line">kernel-lt-4.4.215-1.el7.elrepo.x86_64</span><br><span class="line">kernel-tools-3.10.0-957.el7.x86_64</span><br><span class="line">kernel-lt-devel-4.4.215-1.el7.elrepo.x86_64</span><br></pre></td></tr></table></figure>

<h3 id="5、设置启动"><a href="#5、设置启动" class="headerlink" title="5、设置启动"></a>5、设置启动</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"># 查看启动顺序</span><br><span class="line">[root@localhost ~]# awk -F\&#x27; &#x27;$1==&quot;menuentry &quot; &#123;print $2&#125;&#x27; /etc/grub2.cfg</span><br><span class="line">CentOS Linux (4.4.215-1.el7.elrepo.x86_64) 7 (Core)</span><br><span class="line">CentOS Linux (4.9.9-1.el7.elrepo.x86_64) 7 (Core)</span><br><span class="line">CentOS Linux (3.10.0-957.el7.x86_64) 7 (Core)</span><br><span class="line">CentOS Linux (0-rescue-b91f945269084aa98e8257311ee713c5) 7 (Core)</span><br><span class="line"></span><br><span class="line"># 设置启动顺序</span><br><span class="line">[root@localhost ~]# grub2-set-default 0</span><br><span class="line"></span><br><span class="line"># 重启生效</span><br><span class="line">[root@localhost ~]# reboot</span><br></pre></td></tr></table></figure>

<h2 id="三、源码安装"><a href="#三、源码安装" class="headerlink" title="三、源码安装"></a>三、源码安装</h2><h3 id="1、安装核心软件包"><a href="#1、安装核心软件包" class="headerlink" title="1、安装核心软件包"></a>1、安装核心软件包</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">yum install -y gcc make git ctags ncurses-devel openssl-devel</span><br><span class="line">yum install -y bison flex elfutils-libelf-devel bc</span><br></pre></td></tr></table></figure>

<h3 id="2、创建内核编译目录"><a href="#2、创建内核编译目录" class="headerlink" title="2、创建内核编译目录"></a>2、创建内核编译目录</h3><p>使用 <code>home</code> 下的 <code>kernelbuild</code> 目录</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mkdir ~/kernelbuild</span><br></pre></td></tr></table></figure>

<h3 id="3、获取内核源码"><a href="#3、获取内核源码" class="headerlink" title="3、获取内核源码"></a>3、获取内核源码</h3><blockquote>
<p>清华大学镜像站：<a target="_blank" rel="noopener" href="https://mirror.tuna.tsinghua.edu.cn/kernel/v4.x/?C=M&O=D">https://mirror.tuna.tsinghua.edu.cn/kernel/v4.x/?C=M&amp;O=D</a></p>
<p>其他源码安装包下载地址：<a target="_blank" rel="noopener" href="https://mirrors.edge.kernel.org/pub/linux/kernel/">https://mirrors.edge.kernel.org/pub/linux/kernel/</a></p>
<ul>
<li><code>linux-4.xx.xx.tar.xz</code></li>
<li><code>linux-4.xx.xx.tar.gz</code></li>
<li>这两个格式都可以的，tar.xz压缩率更高，文件更小。</li>
</ul>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">在线下载：wget https://mirror.tuna.tsinghua.edu.cn/kernel/v4.x/linux-4.17.11.tar.xz</span><br></pre></td></tr></table></figure>

<h3 id="4、解压内核代码"><a href="#4、解压内核代码" class="headerlink" title="4、解压内核代码"></a>4、解压内核代码</h3><p>将其解压后进入源码目录:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">tar -xvJf linux-4.17.11.tar.xz</span><br></pre></td></tr></table></figure>

<p>为确保内核树绝对干净，进入内核目录并执行 make mrproper 命令:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">cd linux-4.17.11</span><br><span class="line">make clean &amp;&amp; make mrproper</span><br></pre></td></tr></table></figure>

<h3 id="5、内核配置"><a href="#5、内核配置" class="headerlink" title="5、内核配置"></a>5、内核配置</h3><p>复制当前的内核配置文件</p>
<p><code>config-3.10.0-862.el7.x86_64</code>是我当前环境的内核配置文件，根据实际情况修改</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cp /boot/config-3.10.0-862.el7.x86_64 .config</span><br></pre></td></tr></table></figure>

<blockquote>
<h4 id="高级配置"><a href="#高级配置" class="headerlink" title="高级配置"></a>高级配置</h4><p>y 是启用, n 是禁用, m 是需要时启用.<br><code>make menuconfig</code>: 老的 ncurses 界面，被 nconfig 取代<br><code>make nconfig</code>: 新的命令行 ncurses 界面</p>
</blockquote>
<h3 id="6、编译和安装"><a href="#6、编译和安装" class="headerlink" title="6、编译和安装"></a>6、编译和安装</h3><h4 id="编译内核"><a href="#编译内核" class="headerlink" title="编译内核"></a>编译内核</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">如果你是四核的机器，x可以是8</span><br><span class="line">make -j x</span><br></pre></td></tr></table></figure>

<h4 id="安装内核"><a href="#安装内核" class="headerlink" title="安装内核"></a>安装内核</h4><p>编译完内核后安装:<strong>Warning: 从这里开始，需要 root 权限执行命令，否则会失败.</strong></p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">make modules_install install</span><br></pre></td></tr></table></figure>

<h3 id="7、设置启动"><a href="#7、设置启动" class="headerlink" title="7、设置启动"></a>7、设置启动</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"># 查看启动顺序</span><br><span class="line">[root@localhost ~]# awk -F\&#x27; &#x27;$1==&quot;menuentry &quot; &#123;print $2&#125;&#x27; /etc/grub2.cfg</span><br><span class="line">CentOS Linux (4.17.11-1.el7.elrepo.x86_64) 7 (Core)</span><br><span class="line">CentOS Linux (4.9.9-1.el7.elrepo.x86_64) 7 (Core)</span><br><span class="line">CentOS Linux (3.10.0-957.el7.x86_64) 7 (Core)</span><br><span class="line">CentOS Linux (0-rescue-b91f945269084aa98e8257311ee713c5) 7 (Core)</span><br><span class="line"></span><br><span class="line"># 设置启动顺序</span><br><span class="line">[root@localhost ~]# grub2-set-default 0</span><br><span class="line"></span><br><span class="line"># 重启生效</span><br><span class="line">[root@localhost ~]# reboot</span><br></pre></td></tr></table></figure>

<h2 id="四、卸载-x2F-降级-内核"><a href="#四、卸载-x2F-降级-内核" class="headerlink" title="四、卸载 &#x2F; 降级 内核"></a>四、卸载 &#x2F; 降级 内核</h2><blockquote>
<p>例如:</p>
<p>当系统已存在 LT 内核的 5.4.103 版本时，继续安装 LT 内核的 4.4.215 版本则会提示: <code>package kernel-lt-5.4.103-1.el7.elrepo.x86_64 (which is newer than kernel-lt-4.4.215-1.el7.elrepo.x86_64) is already installed</code></p>
<p>这时就需要进行内核降级，卸载最新版的内核。</p>
</blockquote>
<h3 id="1、查看系统当前内核版本"><a href="#1、查看系统当前内核版本" class="headerlink" title="1、查看系统当前内核版本"></a>1、查看系统当前内核版本</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">[root@localhost ~]# uname -r</span><br><span class="line">5.4.103-1.el7.elrepo.x86_64</span><br></pre></td></tr></table></figure>

<h3 id="2、查看系统中全部内核"><a href="#2、查看系统中全部内核" class="headerlink" title="2、查看系统中全部内核"></a>2、查看系统中全部内核</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">[root@localhost ~]# rpm -qa | grep kernel</span><br><span class="line">kernel-headers-3.10.0-1160.15.2.el7.x86_64</span><br><span class="line">kernel-devel-3.10.0-1160.49.1.el7.x86_64</span><br><span class="line">kernel-tools-libs-3.10.0-957.el7.x86_64</span><br><span class="line">kernel-3.10.0-957.el7.x86_64</span><br><span class="line">kernel-ml-4.9.9-1.el7.elrepo.x86_64</span><br><span class="line">kernel-lt-5.4.103-1.el7.elrepo.x86_64</span><br><span class="line">kernel-tools-3.10.0-957.el7.x86_64</span><br><span class="line">kernel-lt-devel-5.4.103-1.el7.elrepo.x86_64</span><br></pre></td></tr></table></figure>

<h3 id="3、删除指定内核"><a href="#3、删除指定内核" class="headerlink" title="3、删除指定内核"></a>3、删除指定内核</h3><p>此处以删除 LT 内核的 5.4.103 版本为例</p>
<p><strong>注意：</strong>无法卸载当前在用的内核版本。卸载完后不一定需要重启</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">yum remove -y kernel-lt-devel-5.4.103-1.el7.elrepo.x86_64</span><br><span class="line"></span><br><span class="line">yum remove -y kernel-lt-5.4.103-1.el7.elrepo.x86_64</span><br></pre></td></tr></table></figure>

<p>检查卸载后内核版本</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">[root@localhost ~]# rpm -qa | grep kernel</span><br><span class="line">kernel-headers-3.10.0-1160.15.2.el7.x86_64</span><br><span class="line">kernel-devel-3.10.0-1160.49.1.el7.x86_64</span><br><span class="line">kernel-tools-libs-3.10.0-957.el7.x86_64</span><br><span class="line">kernel-3.10.0-957.el7.x86_64</span><br><span class="line">kernel-ml-4.9.9-1.el7.elrepo.x86_64</span><br><span class="line">kernel-tools-3.10.0-957.el7.x86_64</span><br></pre></td></tr></table></figure>
      
    </div>
    <footer class="article-footer">
      
        <div id="donation_div"></div>


<script src="/qingfeng-blog/js/vdonate.js"></script>

<script>
var a = new Donate({
  title: '如果觉得我的文章对您有用，请随意打赏。您的支持将鼓励我继续创作!', // 可选参数，打赏标题
  btnText: 'Donate', // 可选参数，打赏按钮文字
  el: document.getElementById('donation_div'),
  wechatImage: 'http://img.lindaifeng.vip/typora-picgo-tuchaung/20230428150832.png',
  alipayImage: 'http://img.lindaifeng.vip/typora-picgo-tuchaung/20230428150823.png'
});
</script>
      
      
      <div>
        <ul class="post-copyright">
          <li class="post-copyright-author">
          <strong>Post author:  </strong>清峰</a>
          </li>
          <li class="post-copyright-link">
          <strong>Post link:  </strong>
          <a href="/qingfeng-blog/2023/02/08/Linux/CentOS 升级内核/" target="_blank" title="CentOS 升级内核">http://example.com/2023/02/08/Linux/CentOS 升级内核/</a>
          </li>
          <li class="post-copyright-license">
            <strong>Copyright Notice:   </strong>
            All articles in this blog are licensed under <a rel="license" href="https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank" title="Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)">CC BY-NC-ND 4.0</a>
            unless stating additionally.
          </li>
         
        </ul>
<div>

      
      
        
	<div id="comment">
		<!-- 来必力City版安装代码 -->
		<div id="lv-container" data-id="city" data-uid="MTAyMC8yOTQ4MS82MDQ5">
		<script type="text/javascript">
		   (function(d, s) {
		       var j, e = d.getElementsByTagName(s)[0];

		       if (typeof LivereTower === 'function') { return; }

		       j = d.createElement(s);
		       j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
		       j.async = true;

		       e.parentNode.insertBefore(j, e);
		   })(document, 'script');
		</script>
		<noscript>为正常使用来必力评论功能请激活JavaScript</noscript>
		</div>
		<!-- City版安装代码已完成 -->
	</div>



      
      
        
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/qingfeng-blog/tags/centos/" rel="tag">centos</a></li></ul>

      

    </footer>
  </div>
</div>
  
    
<nav id="article-nav">
  
    <a href="/qingfeng-blog/2023/02/28/%E8%BF%90%E7%BB%B4%E5%AE%89%E8%A3%85/Linux%20docker%E5%AE%89%E8%A3%85ELK/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          Linux docker安装ELK
        
      </div>
    </a>
  
  
    <a href="/qingfeng-blog/2023/02/08/%E8%BF%90%E7%BB%B4%E5%AE%89%E8%A3%85/Linux%E5%AE%89%E8%A3%85JDK/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">Linux安装JDK</div>
    </a>
  
</nav>

  
</article>

<!-- Table of Contents -->

  <aside id="toc-sidebar">
    <div id="toc" class="toc-article">
    <strong class="toc-title">Contents</strong>
    
        <ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#CentOS-%E5%8D%87%E7%BA%A7%E5%86%85%E6%A0%B8%E7%9A%84%E4%B8%89%E7%A7%8D%E6%96%B9%E5%BC%8F-yum-x2F-rpm-x2F-%E6%BA%90%E7%A0%81"><span class="nav-number">1.</span> <span class="nav-text">CentOS 升级内核的三种方式(yum&#x2F;rpm&#x2F;源码)</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%B3%A8%E6%84%8F%E4%BA%8B%E9%A1%B9"><span class="nav-number">1.0.1.</span> <span class="nav-text">注意事项</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%B8%80%E3%80%81yum%E5%AE%89%E8%A3%85"><span class="nav-number">1.1.</span> <span class="nav-text">一、yum安装</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1%E3%80%81%E5%AF%BC%E5%85%A5%E4%BB%93%E5%BA%93%E6%BA%90"><span class="nav-number">1.1.1.</span> <span class="nav-text">1、导入仓库源</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2%E3%80%81%E6%9F%A5%E7%9C%8B%E5%8F%AF%E5%AE%89%E8%A3%85%E7%9A%84%E8%BD%AF%E4%BB%B6%E5%8C%85"><span class="nav-number">1.1.2.</span> <span class="nav-text">2、查看可安装的软件包</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3%E3%80%81%E9%80%89%E6%8B%A9-ML-%E6%88%96-LT-%E7%89%88%E6%9C%AC%E5%AE%89%E8%A3%85"><span class="nav-number">1.1.3.</span> <span class="nav-text">3、选择 ML 或 LT 版本安装</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4%E3%80%81%E6%9F%A5%E7%9C%8B%E7%8E%B0%E6%9C%89%E5%86%85%E6%A0%B8%E5%90%AF%E5%8A%A8%E9%A1%BA%E5%BA%8F"><span class="nav-number">1.1.4.</span> <span class="nav-text">4、查看现有内核启动顺序</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#5%E3%80%81%E4%BF%AE%E6%94%B9%E9%BB%98%E8%AE%A4%E5%90%AF%E5%8A%A8%E9%A1%B9"><span class="nav-number">1.1.5.</span> <span class="nav-text">5、修改默认启动项</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%BA%8C%E3%80%81RPM%E5%AE%89%E8%A3%85"><span class="nav-number">1.2.</span> <span class="nav-text">二、RPM安装</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1%E3%80%81%E6%9F%A5%E6%89%BE%E7%89%88%E6%9C%AC"><span class="nav-number">1.2.1.</span> <span class="nav-text">1、查找版本</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2%E3%80%81%E5%85%B1%E9%9C%80%E8%A6%81%E4%B8%8B%E8%BD%BD%E4%B8%89%E4%B8%AA%E7%B1%BB%E5%9E%8B-rpm"><span class="nav-number">1.2.2.</span> <span class="nav-text">2、共需要下载三个类型 rpm</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3%E3%80%81%E5%AE%89%E8%A3%85%E5%86%85%E6%A0%B8"><span class="nav-number">1.2.3.</span> <span class="nav-text">3、安装内核</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4%E3%80%81%E7%A1%AE%E8%AE%A4%E5%B7%B2%E5%AE%89%E8%A3%85%E5%86%85%E6%A0%B8%E7%89%88%E6%9C%AC"><span class="nav-number">1.2.4.</span> <span class="nav-text">4、确认已安装内核版本</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#5%E3%80%81%E8%AE%BE%E7%BD%AE%E5%90%AF%E5%8A%A8"><span class="nav-number">1.2.5.</span> <span class="nav-text">5、设置启动</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%B8%89%E3%80%81%E6%BA%90%E7%A0%81%E5%AE%89%E8%A3%85"><span class="nav-number">1.3.</span> <span class="nav-text">三、源码安装</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1%E3%80%81%E5%AE%89%E8%A3%85%E6%A0%B8%E5%BF%83%E8%BD%AF%E4%BB%B6%E5%8C%85"><span class="nav-number">1.3.1.</span> <span class="nav-text">1、安装核心软件包</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2%E3%80%81%E5%88%9B%E5%BB%BA%E5%86%85%E6%A0%B8%E7%BC%96%E8%AF%91%E7%9B%AE%E5%BD%95"><span class="nav-number">1.3.2.</span> <span class="nav-text">2、创建内核编译目录</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3%E3%80%81%E8%8E%B7%E5%8F%96%E5%86%85%E6%A0%B8%E6%BA%90%E7%A0%81"><span class="nav-number">1.3.3.</span> <span class="nav-text">3、获取内核源码</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4%E3%80%81%E8%A7%A3%E5%8E%8B%E5%86%85%E6%A0%B8%E4%BB%A3%E7%A0%81"><span class="nav-number">1.3.4.</span> <span class="nav-text">4、解压内核代码</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#5%E3%80%81%E5%86%85%E6%A0%B8%E9%85%8D%E7%BD%AE"><span class="nav-number">1.3.5.</span> <span class="nav-text">5、内核配置</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E9%AB%98%E7%BA%A7%E9%85%8D%E7%BD%AE"><span class="nav-number">1.3.5.1.</span> <span class="nav-text">高级配置</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#6%E3%80%81%E7%BC%96%E8%AF%91%E5%92%8C%E5%AE%89%E8%A3%85"><span class="nav-number">1.3.6.</span> <span class="nav-text">6、编译和安装</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E7%BC%96%E8%AF%91%E5%86%85%E6%A0%B8"><span class="nav-number">1.3.6.1.</span> <span class="nav-text">编译内核</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%AE%89%E8%A3%85%E5%86%85%E6%A0%B8"><span class="nav-number">1.3.6.2.</span> <span class="nav-text">安装内核</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#7%E3%80%81%E8%AE%BE%E7%BD%AE%E5%90%AF%E5%8A%A8"><span class="nav-number">1.3.7.</span> <span class="nav-text">7、设置启动</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%9B%9B%E3%80%81%E5%8D%B8%E8%BD%BD-x2F-%E9%99%8D%E7%BA%A7-%E5%86%85%E6%A0%B8"><span class="nav-number">1.4.</span> <span class="nav-text">四、卸载 &#x2F; 降级 内核</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1%E3%80%81%E6%9F%A5%E7%9C%8B%E7%B3%BB%E7%BB%9F%E5%BD%93%E5%89%8D%E5%86%85%E6%A0%B8%E7%89%88%E6%9C%AC"><span class="nav-number">1.4.1.</span> <span class="nav-text">1、查看系统当前内核版本</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2%E3%80%81%E6%9F%A5%E7%9C%8B%E7%B3%BB%E7%BB%9F%E4%B8%AD%E5%85%A8%E9%83%A8%E5%86%85%E6%A0%B8"><span class="nav-number">1.4.2.</span> <span class="nav-text">2、查看系统中全部内核</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3%E3%80%81%E5%88%A0%E9%99%A4%E6%8C%87%E5%AE%9A%E5%86%85%E6%A0%B8"><span class="nav-number">1.4.3.</span> <span class="nav-text">3、删除指定内核</span></a></li></ol></li></ol></li></ol>
    
    </div>
  </aside>


</section>
        
      </div>
      
      <footer id="footer">
  

  <div class="container">
      	<div class="row">
	      <!-- <p> Powered by <a href="http://hexo.io/" target="_blank">Hexo</a> and <a href="https://github.com/iTimeTraveler/hexo-theme-hiker" target="_blank">Hexo-theme-hiker</a> </p> -->
	      <p>May there be no bug in the world！</p>
        <p id="copyRightEn">Copyright &copy; 2022 - 2023 All Rights Reserved.</p>
	      
	      
    		<p class="busuanzi_uv">
				UV : <span id="busuanzi_value_site_uv"></span> |  
				PV : <span id="busuanzi_value_site_pv"></span>
		    </p>
  		   
		</div>

		
  </div>
</footer>


<!-- min height -->

<script>
    var wrapdiv = document.getElementById("wrap");
    var contentdiv = document.getElementById("content");
    var allheader = document.getElementById("allheader");

    wrapdiv.style.minHeight = document.body.offsetHeight + "px";
    if (allheader != null) {
      contentdiv.style.minHeight = document.body.offsetHeight - allheader.offsetHeight - document.getElementById("footer").offsetHeight + "px";
    } else {
      contentdiv.style.minHeight = document.body.offsetHeight - document.getElementById("footer").offsetHeight + "px";
    }
</script>
    </div>
    <!-- <nav id="mobile-nav">
  
    <a href="/qingfeng-blog/" class="mobile-nav-link">首页</a>
  
    <a href="/qingfeng-blog/categories" class="mobile-nav-link">分类</a>
  
    <a href="/qingfeng-blog/tags" class="mobile-nav-link">标签</a>
  
</nav> -->
    

<!-- mathjax config similar to math.stackexchange -->

<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    tex2jax: {
      inlineMath: [ ['$','$'], ["\\(","\\)"] ],
      processEscapes: true
    }
  });
</script>

<script type="text/x-mathjax-config">
    MathJax.Hub.Config({
      tex2jax: {
        skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
      }
    });
</script>

<script type="text/x-mathjax-config">
    MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for(i=0; i < all.length; i += 1) {
            all[i].SourceElement().parentNode.className += ' has-jax';
        }
    });
</script>

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>


  
<link rel="stylesheet" href="/qingfeng-blog/fancybox/jquery.fancybox.css">

  
<script src="/qingfeng-blog/fancybox/jquery.fancybox.pack.js"></script>




<script src="/qingfeng-blog/js/scripts.js"></script>



  
<script src="/qingfeng-blog/js/home.js"></script>




  
<script src="/qingfeng-blog/js/dialog.js"></script>









	<div style="display: none;">
    <script src="https://s95.cnzz.com/z_stat.php?id=1260716016&web_id=1260716016" language="JavaScript"></script>
  </div>



	<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js">
	</script>






  </div>

  <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h2 class="modal-title" id="myModalLabel">设置</h2>
      </div>
      <hr style="margin-top:0px; margin-bottom:0px; width:80%; border-top: 3px solid #000;">
      <hr style="margin-top:2px; margin-bottom:0px; width:80%; border-top: 1px solid #000;">


      <div class="modal-body">
          <div style="margin:6px;">
            <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne" onclick="javascript:setFontSize();" aria-expanded="true" aria-controls="collapseOne">
              正文字号大小
            </a>
          </div>
          <div id="collapseOne" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingOne">
          <div class="panel-body">
            您已调整页面字体大小
          </div>
        </div>
      


          <div style="margin:6px;">
            <a data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" onclick="javascript:setBackground();" aria-expanded="true" aria-controls="collapseTwo">
              夜间护眼模式
            </a>
        </div>
          <div id="collapseTwo" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingTwo">
          <div class="panel-body">
            夜间模式已经开启，再次单击按钮即可关闭 
          </div>
        </div>

        <div>
            <a data-toggle="collapse" data-parent="#accordion" href="#collapseThree" aria-expanded="true" aria-controls="collapseThree">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;关 于&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a>
        </div>
         <div id="collapseThree" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingThree">
          <div class="panel-body">
            清峰小栈
          </div>
          <div class="panel-body">
            Copyright © 2023 清峰 All Rights Reserved.
          </div>
        </div>
      </div>


      <hr style="margin-top:0px; margin-bottom:0px; width:80%; border-top: 1px solid #000;">
      <hr style="margin-top:2px; margin-bottom:0px; width:80%; border-top: 3px solid #000;">
      <div class="modal-footer">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
      </div>
    </div>
  </div>
</div>
  
  <a id="rocket" href="#top" class=""></a>
  <script type="text/javascript" src="/qingfeng-blog/js/totop.js?v=1.0.0" async=""></script>
  
    <a id="menu-switch"><i class="fa fa-bars fa-lg"></i></a>
  
</body>
</html>